﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using Common;
using CrystalDecisions.CrystalReports.Engine;

namespace CNCSoft.ErpApps.TMS.longGiaoVu
{
    public partial class frmDoanhThuVaKetQuaNhanVienTuNgayDenNgay : Form
    {
        SqlConnection conn = new SqlConnection(GlobalVariable.WSInfo.ConnectionString);
        DataSet ds = new DataSet();
        string _userid = GlobalVariable.WSInfo.UserID;

        public frmDoanhThuVaKetQuaNhanVienTuNgayDenNgay()
        {
            InitializeComponent();
        }

        private void frmDoanhThuVaKetQuaNhanVienTuNgayDenNgay_Load(object sender, EventArgs e)
        {
            
        }

        private void btnXem_Click(object sender, EventArgs e)
        {
            Validation();
            string userid = _userid;
            string namereport = "Report_DoanhThuVaKetQuaCuaNhanVienTuNgayDenNgay";
            DateTime tungay = Convert.ToDateTime(dateEdit_TuNgay.EditValue);
            DateTime denngay = Convert.ToDateTime(dateEdit_DenNgay.EditValue);
            PrintData(userid, tungay, denngay, namereport);
        }

        private void btnDanhSachNguoiDuocTuVan_Click(object sender, EventArgs e)
        {
            Validation();
            string userid = _userid;
            string namereport = "myrpt_DanhSachNguoiByCounsellorTuNgayDenNgay";
            DateTime tungay = Convert.ToDateTime(dateEdit_TuNgay.EditValue);
            DateTime denngay = Convert.ToDateTime(dateEdit_DenNgay.EditValue);
            PrintData(userid, tungay, denngay, namereport);
        }

        private void btnDanhSachNguoiDongTien_Click(object sender, EventArgs e)
        {
            Validation();
            string userid = _userid;
            string namereport = "myrpt_DanhSachHocVienByCounsellorTuNgayTuVanDenNgayTuVan";
            DateTime tungay = Convert.ToDateTime(dateEdit_TuNgay.EditValue);
            DateTime denngay = Convert.ToDateTime(dateEdit_DenNgay.EditValue);
            PrintData(userid, tungay, denngay, namereport);
        }

        private void btnDanhSachNguoiChuaDongTien_Click(object sender, EventArgs e)
        {
            Validation();
            string userid = _userid;
            string namereport = "myrpt_DanhSachNguoiChuaDongTienByTuVanTuNgayDenNgayTuVan";
            DateTime tungay = Convert.ToDateTime(dateEdit_TuNgay.EditValue);
            DateTime denngay = Convert.ToDateTime(dateEdit_DenNgay.EditValue);
            PrintData(userid, tungay, denngay, namereport);
        }
        #region "Coding"
        private void PrintData(string userid, DateTime tungay, DateTime denngay, string namereport)
        {
            try
            {
                btnXem.Enabled = false;
                //Load Report
                ReportDocument rpt = new ReportDocument();
                if(GlobalVariable.WSInfo.CompanyID.ToLower() == "english")
                    rpt.Load(Application.StartupPath + "\\Report\\" + namereport + ".rpt");
                //Set connection
                PublicFunction.SetDBLogonForReport(rpt);
                //Set parameters
                PublicFunction.SetParameter(rpt, "@userid", userid);
                PublicFunction.SetParameter(rpt, "@tungay", tungay);
                PublicFunction.SetParameter(rpt, "@denngay", denngay);
                //View report
                frmPrintPreview printpreview = new frmPrintPreview(rpt);
                printpreview.ShowDialog();
                printpreview.Dispose();

                rpt.Dispose();
                btnXem.Enabled = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void Validation()
        {
            try
            {
                if (dateEdit_TuNgay.Text == "")
                {
                    MessageBox.Show("Bạn chưa chọn ngày bắt đầu");
                    return;
                }
                if(dateEdit_DenNgay.Text == "")
                {
                    MessageBox.Show("Bạn chưa chọn ngày kết thúc");
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        #endregion
    }
}
